package lab03.test08;
import java.io.*;


public class Test08 {
    public static void main(String[] args) {
        String str1=null;
        String str2=null;
        try {
            FileInputStream fileInputStream1=new FileInputStream("E:\\233.txt");
            FileInputStream fileInputStream2=new FileInputStream("E:\\433.txt");
            FileOutputStream fileOutputStream=new FileOutputStream("E:\\111.txt");
            byte[] a=new byte[fileInputStream1.available()];//将字节转换成数组,字节的长度就是数组长度
            byte[] b=new byte[fileInputStream2.available()];

while (fileInputStream1.read(a)!=-1){
    str1=new String(a);
}
   while (fileInputStream2.read(b)!=-1){
    str2=new String(b);

   }
            //通过字节输入流读取字节
            //括号里面是读取的字节
            ByteArrayInputStream array1=new ByteArrayInputStream(str1.getBytes());

            ByteArrayInputStream array2=new ByteArrayInputStream(str2.getBytes());


            int ch1,ch2;
while ((ch1=array1.read())!=-1&&(ch2=array2.read())!=-1){
fileOutputStream.write(ch1);
fileOutputStream.write(ch2);

}
           if (str1.getBytes().length>str2.getBytes().length){
    array1.skip(str2.getBytes().length);//跳跃的字节长度数
               while ((ch1=array1.read())!=-1) {

                   fileOutputStream.write(ch1);
               }
               System.out.println("写入成功1");
           }
            else {
               array2.skip(str1.getBytes().length);//跳跃的字节长度数
               while ((ch2=array2.read())!=-1){
                   fileOutputStream.write(ch2);
               }
               System.out.println("写入成功2");
           }
        }

        catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
